package com.sushi.controller;

import com.sushi.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Controller
public class Controller9 {
    @RequestMapping("/test9")
    @ResponseBody
    public String test9() {
        System.out.println("页面 9");
        return "{'name':'zhangsan', 'age':'13'}";
    }

    @RequestMapping("/testGet")
    @ResponseBody
    public String testGet(@Validated String name, @Validated String location) {
        System.out.println("name:" + name + "  Location:" + location);
        return "{'name':'" + name + "', 'location':'" + location + "'}";
    }
    @RequestMapping(value = "/testPost", method = RequestMethod.POST)
    @ResponseBody
    public String testPost(@Validated String name, @Validated String location) {
        System.out.println("name:" + name + "  Location:" + location);
        return "{'name':'" + name + "', 'location':'" + location + "', 'tips':'额外的'}";
    }

    @RequestMapping(value = "/testPojoParam")
    @ResponseBody
    public String testPojoParam(User user) {
        System.out.println(user);
        return user.toString();
    }

    @RequestMapping(value = "/testPojo2Param", method = RequestMethod.POST)
    @ResponseBody
    public String testPojo2Param(User user) {
        System.out.println(user);
        return user.toString();
    }

    @RequestMapping(value = "/testList", method = RequestMethod.POST)
    @ResponseBody
    public String testList(String[] strs) {
        System.out.println("数组：" + Arrays.toString(strs));
        return Arrays.toString(strs);
    }
    @RequestMapping(value = "/testList2", method = RequestMethod.POST)
    @ResponseBody
    public String testList2(@RequestParam List<String> list) {
        System.out.println("集合:" + list);
        return list.toString();
    }

    @RequestMapping(value = "/jsonParam")
    @ResponseBody
    public String jsonParam(@RequestBody List<User> users) {
        System.out.println(users);
        return "Success!";
    }

}
